import request from '@/utils/request'

/**
 * 获取角色列表
 * @param {*} page 页码
 * @param {*} pagesize 每页几条
 */
export const reqGetRoleList = (page, pagesize = 5) => {
  return request({
    method: 'get',
    url: `/sys/role`,
    params: {
      page,
      pagesize
    }
  })
}

/**
 * 根据id删除角色
 * @param {*} id 角色id
 */
export const reqDelRole = (id) => request({
  method: 'delete',
  url: `/sys/role/${id}`
})

/**
 * 添加角色
 * @param {*} form { name , description }
 */
export const reqAddRole = form => {
  return request({
    method: 'post',
    url: '/sys/role',
    data: form
  })
}

/**
 * 根据id获取角色详情
 * @param {*} id 角色id
 */
export const reqGetRoleDetail = id => request({
  method: 'get',
  url: `/sys/role/${id}`
})

/**
 * 更新角色详情
 * @param {*} form { id, ..... }
 */
export const reqUpdateRole = (form) => request({
  method: 'put',
  url: '/sys/role/' + form.id,
  data: form
})

/**
 * 给角色分配权限
 * @param {*} id 角色id
 * @param {*} permIds 勾选的权限id组成的数组
 */
export const reqAssignPerm = (id, permIds) => {
  return request({
    method: 'put',
    url: '/sys/role/assignPrem',
    data: {
      id,
      permIds
    }
  })
}
